package com.jams.rbac.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jams.common.core.system.JamsResponse;
import com.jams.rbac.api.entity.UserRole;
import com.jams.rbac.service.UserRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 用户角色表
 *
 * @author linxb
 * @date 2020-01-07 19:23:10
 */
@RestController
@AllArgsConstructor
@RequestMapping("/userrole")
@Api(value = "userrole", tags = "用户角色表管理")
public class UserRoleController {

    private final  UserRoleService userRoleService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param userRole 用户角色表
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    public JamsResponse getUserRolePage(Page page, UserRole userRole) {
        return JamsResponse.ok(userRoleService.page(page, Wrappers.query(userRole)));
    }

    /**
     * 列表查询
     * @param userRole 用户角色表
     * @return
     */
    @ApiOperation(value = "列表查询", notes = "列表查询")
    @GetMapping("/list")
    public JamsResponse getUserRoleList(UserRole userRole) {
        return JamsResponse.ok(userRoleService.list(Wrappers.query(userRole)));
    }

    /**
     * 通过id查询用户角色表
     * @param userId id
     * @return JamsResponse
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{userId}")
    public JamsResponse getById(@PathVariable("userId") Long userId) {
        return JamsResponse.ok(userRoleService.getById(userId));
    }

    /**
     * 新增用户角色表
     * @param userRole 用户角色表
     * @return JamsResponse
     */
    @ApiOperation(value = "新增用户角色表", notes = "新增用户角色表")
    @PostMapping
    public JamsResponse save(@RequestBody UserRole userRole) {
        return JamsResponse.ok(userRoleService.save(userRole));
    }

    /**
     * 修改用户角色表
     * @param userRole 用户角色表
     * @return JamsResponse
     */
    @ApiOperation(value = "修改用户角色表", notes = "修改用户角色表")
    @PutMapping
    public JamsResponse updateById(@RequestBody UserRole userRole) {
        return JamsResponse.ok(userRoleService.updateById(userRole));
    }

    /**
     * 通过id删除用户角色表
     * @param userId id
     * @return JamsResponse
     */
    @ApiOperation(value = "通过id删除用户角色表", notes = "通过id删除用户角色表")
    @DeleteMapping("/{userId}")
    public JamsResponse removeById(@PathVariable Long userId) {
        return JamsResponse.ok(userRoleService.removeById(userId));
    }

}
